<?php
/**
 * Page Template
 *
 * Loaded by main_page=index<br />
 * Displays product-listing when a particular category/subcategory is selected for browsing
 *
 * @package templateSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_index_product_list.php 15589 2010-02-27 15:03:49Z ajeh $
 */
?>
<div class="centerColumn" id="indexProductList">

<h1 id="productListHeading"><?php echo $breadcrumb->last(); ?></h1>

<?php
if (PRODUCT_LIST_CATEGORIES_IMAGE_STATUS == 'true') {
// categories_image
  if ($categories_image = zen_get_categories_image($current_category_id)) {
?>
<div id="categoryImgListing" class="categoryImg"><?php echo zen_image(DIR_WS_IMAGES . $categories_image, '', CATEGORY_ICON_IMAGE_WIDTH, CATEGORY_ICON_IMAGE_HEIGHT); ?></div>
<?php
  }
} // categories_image
?>

<?php
// categories_description
    if ($current_categories_description != '') {
?>
<div id="indexProductListCatDescription" class="content"><?php echo $current_categories_description;  ?></div>
<?php } // categories_description ?>

<?php
  $check_for_alpha = $listing_sql;
  $check_for_alpha = $db->Execute($check_for_alpha);

  if ($do_filter_list || ($check_for_alpha->RecordCount() > 0 && PRODUCT_LIST_ALPHA_SORTER == 'true')) {
  $form = zen_draw_form('filter', zen_href_link(FILENAME_DEFAULT), 'get', 'id="filterForm"') . '<label class="inputLabel filterLabel">' .TEXT_SHOW . '</label>';
?>

<?php
  echo $form;
  echo zen_draw_hidden_field('main_page', FILENAME_DEFAULT);
  echo zen_hide_session_id();
?>
<?php
  // draw cPath if known
  if (!$getoption_set) {
    echo zen_draw_hidden_field('cPath', $cPath);
  } else {
    // draw manufacturers_id
    echo zen_draw_hidden_field($get_option_variable, $_GET[$get_option_variable]);
  }

  // draw music_genre_id
  if (isset($_GET['music_genre_id']) && $_GET['music_genre_id'] != '') echo zen_draw_hidden_field('music_genre_id', $_GET['music_genre_id']);

  // draw record_company_id
  if (isset($_GET['record_company_id']) && $_GET['record_company_id'] != '') echo zen_draw_hidden_field('record_company_id', $_GET['record_company_id']);

  // draw typefilter
  if (isset($_GET['typefilter']) && $_GET['typefilter'] != '') echo zen_draw_hidden_field('typefilter', $_GET['typefilter']);

  // draw manufacturers_id if not already done earlier
  if ($get_option_variable != 'manufacturers_id' && isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] > 0) {
    echo zen_draw_hidden_field('manufacturers_id', $_GET['manufacturers_id']);
  }

  // draw sort
  echo zen_draw_hidden_field('sort', $_GET['sort']);

  // draw filter_id (ie: category/mfg depending on $options)
  if ($do_filter_list) {
    echo zen_draw_pull_down_menu('filter_id', $options, (isset($_GET['filter_id']) ? $_GET['filter_id'] : ''), 'onchange="this.form.submit()"');
  }

  // draw alpha sorter
  require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCT_LISTING_ALPHA_SORTER));

  $sorter = array();
  $sorter = array(
      array(
        'id' => '20a',
        'text' => TEXT_SORT_BY
      ),array(
        'id' => '2a',
        'text' => TEXT_NAME_ASC
      ),array(
       'id' => '2d',
        'text' => TEXT_NAME_DESC
      ),array(
       'id' => '3a',
        'text' => TEXT_PRICE_ASC
      ),array(
       'id' => '3d',
        'text' => TEXT_PRICE_DESC
      )
  );

  echo zen_draw_pull_down_menu('sort', $sorter, (isset($_GET['sort']) ? $_GET['sort'] : ''), 'onchange="this.form.submit()"');      
?>
<div class="grid-list">
<div class="m-btn-group">
    <a id="gridSwitch" data-my-tooltip="tooltip" title="<?php echo TEXT_GRID; ?>" href="javascript:display('grid');" class="m-btn icn-only"><i class="icon-th"></i></a>
    <a id="listSwitch" data-my-tooltip="tooltip" title="<?php echo TEXT_LIST; ?>" href="javascript:void(0);" class="m-btn disabled icn-only"><i class="icon-th-list"></i></a>
</div>
</div>    
<script type="text/javascript"><!--
    function display(view) {
        if (view == 'list') {
            $('.productsGridWrapper').attr('class', 'productsListWrapper').removeClass('row-fluid');
            $('.productsListWrapper > .gridItem').attr('class', 'productList').addClass('row-fluid').removeClass('centeredContent');
            
            $('.productList').each(function(index, element) {
                html = '';
                
                var image = $(element).find('.listingProductImage').html();
                
                if (image != null) { 
                    html += '<div class="span3 listingProductImage centeredContent">' + image + '</div>';
                }
                
                html += '  <div class="span6 listingProductDetails">	';	
                html += '  <h3 class="itemTitle">' + $(element).find('.itemTitle').html() + '</h3>';
                html += '  <div class="listingDescription">' + $(element).find('.listingDescription').html() + '</div>';
                html += '  </div>	';
                
                var ratings = $(element).find('.rating').html();
                
                var price = $(element).find('.price').html();
                
                html += '<div class="span3 listingProductsAction centeredContent">';
                if (ratings != null) {
                    html += '<p class="rating">' + ratings  + '</p>';
                }   
                if (price != null) {
                    html += '<p class="price">' + price  + '</p>';
                }
                html += '<div class="btnCart">' + $(element).find('.btnCart').html() + '</div>';

                html += '</div>';			
                    
                $(element).html(html);
                
            });		
            $('.grid-list').html('<div class="m-btn-group"><a id="gridSwitch" href="javascript:display(\'grid\');" class="m-btn icn-only" data-my-tooltip="tooltip" title="<?php echo TEXT_GRID; ?>"><i class="icon-th"></i></a><a id="listSwitch" href="javascript:void(0);" class="m-btn disabled icn-only" data-my-tooltip="tooltip" title="<?php echo TEXT_LIST; ?>"><i class="icon-th-list"></i></a></div>'); 
            $.cookie('display', 'list', { expires: 7, path: '/' });
        } else {
            $('.productsListWrapper .productList').attr('class', 'gridItem').addClass('centeredContent');
            $('.productsListWrapper').attr('class', 'productsGridWrapper');
            $('.productsGridWrapper').toggleClass('row-fluid');
            $('.productsGridWrapper .gridItem').each(function(index, element) {
                html = '<div class="gridItemInner">';
                
                var image = $(element).find('.listingProductImage').html();
                
                if (image != null) {
                    html += '<div class="listingProductImage image">' + image + '</div>';
                }
                
                html += '<h3 class="itemTitle name">' + $(element).find('.itemTitle').html() + '</h3>';
                html += '<div class="listingDescription description" style="display:none">' + $(element).find('.listingDescription').html() + '</div>';
                
                var ratings = $(element).find('.rating').html();
                if (ratings != null) {
                    html += '<p class="rating nomargin">' + ratings  + '</p>';
                }
                
                var price = $(element).find('.price').html();
                
                if (price != null) {
                    html += '<p class="price">' + price  + '</p>';
                }
                            
                html += '<div class="btnCart">' + $(element).find('.btnCart').html() + '</div>'; 
                
                html += '</div>';
                $(element).html(html);
            });	
                        
            $('.grid-list').html('<div class="m-btn-group"><a id="gridSwitch" href="javascript:void(0);" class="m-btn disabled icn-only" data-my-tooltip="tooltip" title="<?php echo TEXT_GRID; ?>"><i class="icon-th"></i></a><a id="listSwitch" href="javascript:display(\'list\');" class="m-btn icn-only" data-my-tooltip="tooltip" title="<?php echo TEXT_LIST; ?>"><i class="icon-th-list"></i></a></div>');
            $.cookie('display', 'grid', { expires: 7, path: '/' }); 
        }
    }
    <?php if(defined('REVELATION_DEFAULT_VIEW') && REVELATION_DEFAULT_VIEW == 'list') { ?>
      if($.cookie('display')){
        jQuery(function($){display($.cookie('display'));});
      }else{
        jQuery(function($){display('list');});
      }
    <?php }else{ ?>
      if($.cookie('display')){
        jQuery(function($){display($.cookie('display'));});
      }else{
        jQuery(function($){display('grid');});
      }
    <?php } ?>
    //--></script>       
</form>
<?php
  }
?>
<br class="clearBoth" />

<?php
/**
 * require the code for listing products
 */
 require($template->get_template_dir('tpl_modules_product_listing.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_product_listing.php');
?>


<?php
//// bof: categories error
if ($error_categories==true) {
  // verify lost category and reset category
  $check_category = $db->Execute("select categories_id from " . TABLE_CATEGORIES . " where categories_id='" . $cPath . "'");
  if ($check_category->RecordCount() == 0) {
    $new_products_category_id = '0';
    $cPath= '';
  }
?>

<?php
$show_display_category = $db->Execute(SQL_SHOW_PRODUCT_INFO_MISSING);

while (!$show_display_category->EOF) {
?>

<?php
  if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_MISSING_FEATURED_PRODUCTS') { ?>
<?php
/**
 * display the Featured Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_featured_products.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_featured_products.php'); ?>
<?php } ?>

<?php
  if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_MISSING_SPECIALS_PRODUCTS') { ?>
<?php
/**
 * display the Special Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_specials_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_specials_default.php'); ?>
<?php } ?>

<?php
  if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_MISSING_NEW_PRODUCTS') { ?>
<?php
/**
 * display the New Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>
<?php } ?>

<?php
  if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_MISSING_UPCOMING') {
    include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_UPCOMING_PRODUCTS));
  }
?>
<?php
  $show_display_category->MoveNext();
} // !EOF
?>
<?php } //// eof: categories error ?>

<?php
//// bof: categories
$show_display_category = $db->Execute(SQL_SHOW_PRODUCT_INFO_LISTING_BELOW);
if ($error_categories == false and $show_display_category->RecordCount() > 0) {
?>

<?php
  $show_display_category = $db->Execute(SQL_SHOW_PRODUCT_INFO_LISTING_BELOW);
  while (!$show_display_category->EOF) {
?>

<?php
    if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_LISTING_BELOW_FEATURED_PRODUCTS') { ?>
<?php
/**
 * display the Featured Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_featured_products.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_featured_products.php'); ?>
<?php } ?>

<?php
    if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_LISTING_BELOW_SPECIALS_PRODUCTS') { ?>
<?php
/**
 * display the Special Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_specials_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_specials_default.php'); ?>
<?php } ?>

<?php
    if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_LISTING_BELOW_NEW_PRODUCTS') { ?>
<?php
/**
 * display the New Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>
<?php } ?>

<?php
    if ($show_display_category->fields['configuration_key'] == 'SHOW_PRODUCT_INFO_LISTING_BELOW_UPCOMING') {
      include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_UPCOMING_PRODUCTS));
    }
?>
<?php
  $show_display_category->MoveNext();
  } // !EOF
?>

<?php
} //// eof: categories
?>

</div>